<template>
    <div class="app-container">
      <table-pro
        :isShowIdColumn="false"
        idColumnName="id"
        :columns="columns"
        dialog-title="证书"
        :table-request-fn="listCert"
        :create-fn="addCert"
        :update-fn="updateCert"
        :delete-fn="delCert"
        :isShowButtonList="false"
        :tableParams="{cerValidityFlag:1}"
        :form-params="{ cerCategory: '1' }"
      />
    </div>
  </template>
  
  <script>
  import {
    listCert,
    getCert,
    addCert,
    updateCert,
    delCert,
  } from "@/api/cert/index.js";
  
  export default {
    name: "Expire",
    dicts: ["sys_normal_disable", "cert_company", "cert_type","cer_state","cer_from","cer_class","cer_category"],
    data() {
      return {
        personal: true,
      };
    },
    computed: {
      columns() {
      return [
        {
          title: "证书分类",
          field: "cerCategory",
          type: "radio",
          add: true,
          change: this.onCertTypeChange,
          options: this.dict.type.cer_category,
          disabled: true,
        },
        {
          title: "持证人",
          field: "cerLicensee",
          add: this.personal ? [{ required: true, message: "请输入" }] : false,
          
          hidden:true
        },
        {
          title: "身份证号",
          field: "idNumbers",
          add: this.personal ? [{ required: true, message: "请输入" }] : false,
          
          hidden:true
        },
        {
          title: "证书类型",
          field: "cerClass",
          add: [{ required: true, message: "请输入" }],
          
          type: "select",
          options: this.dict.type.cer_class,
        },
        {
          title: "证书形式",
          field: "cerFrom",
          add: [{ required: true, message: "请输入" }],
          type: "select",
          options: this.dict.type.cer_from,
        },
        {
          title: "证书编号",
          field: "cerNumber",
          add: [{ required: true, message: "请输入" }],
          add: true,
          hidden:true
        },
        {
          title: "证书名称",
          field: "cerName",
          add: [{ required: true, message: "请输入" }],
          add: true,
        },
        {
          title: "发证单位",
          field: "cerUnit",
          add: true,
        },
        {
          title: "发证时间",
          field: "cerStartTime",
          type: "date",
          add: true,
        },
        {
          title: "过期时间",
          field: "cerValidity",
          type: "date",
          add: true,
        },
        {
          title: "过期时间",
          field: "cerValidity",
          type: "daterange",
          
          hidden:true
        },
        {
          title: "证书状态",
          field: "cerState",
          add: true,
          
          type: "select",
          options: this.dict.type.cer_state,
        },
        // {
        //   title: "证书性质",
        //   field: "status8",
        //   add: true,
        //   
        //   type: "select",
        //   options: this.dict.type.cer_from,
        // },
        {
          title: "注册单位",
          field: "companyId",
          add: true,
          
          type: "select",
          options: this.dict.type.cert_company,
        },
        // {
        //   title: "转入时间",
        //   field: "date11",
        //   type: "date",
        //   add: true,
        // },
        {
          title: "年检时间",
          field: "annuallTime",
          type: "date",
          add: true,
          hidden:true
        },
        {
          title: "证书存放地",
          field: "cerStore",
          add: true,
          hidden:true
        },
        {
          title: "保管人",
          field: "cerKeeper",
          type:"user",
          hidden:true
        },
        {
          title: "保管人",
          field: "cerKeeperId",
          hidden:true,
          add:true,
          type:"user"
        },
        {
          title: "保管部门",
          field: "dept",
          type:"department",
          hidden:true
        },
        {
          title: "保管部门",
          field: "deptId",
          hidden:true,
          add:true,
          type:"department"
        },
        {
          title: "备注",
          field: "remark",
          add: true,
          hidden:true,
          formProps: { type: "textarea" },
        },
        {
          title: "附件",
          field: "attachments",
          add: true,
          type: "img",
          render:(item)=>{
            if(item.attachments){
              return item.attachments.split(",")
            }else{
              return []
            }
          }
        },
        {
          actions: [
            { type: "edit", beforeCallback: this.onBeforeEditCallback },
            { type: "delete" },{ type: "detail" },
          ],
        },
      ];
    },
    },
    created() {},
    methods: {
      listCert:listCert,
      getCert:getCert,
      addCert:addCert,
      updateCert:updateCert,
      delCert:delCert,
      onCertTypeChange(val) {
        this.personal = val == 1;
      },
      onBeforeEditCallback(item) {
        this.personal = true;
        return item;
      },
    },
  };
  </script>
  